{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import os"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def findfiles(stri,path):\n",
    "    '''找到path目录下及其及目录下的所有包含stri的文件并打印其相对路径'''\n",
    "    abspath = os.path.abspath(path)\n",
    "    a = os.listdir(abspath)\n",
    "    for i in a:\n",
    "        if os.path.isfile(i) and stri in i:\n",
    "            print(os.path.dirname(i))\n",
    "        if os.path.isdir(i):\n",
    "            findfiles(stri,i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "findfiles('.py','.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "''"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.path.dirname('findFile.py')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['.git',\n",
       " '.ipynb_checkpoints',\n",
       " '.spyderproject',\n",
       " '.spyderworkspace',\n",
       " 'euler43.py',\n",
       " 'euler44.py',\n",
       " 'euler45.py',\n",
       " 'euler46.py',\n",
       " 'euler47.py',\n",
       " 'euler48.py',\n",
       " 'euler49.py',\n",
       " 'euler50.py',\n",
       " 'euler51.py',\n",
       " 'EulerProject.ipynb',\n",
       " 'EulerProject_39.ipynb',\n",
       " 'Euler_11_data.txt',\n",
       " 'findFile.py',\n",
       " 'get_pre_score.m',\n",
       " 'p042_words.txt',\n",
       " 'sim_pearson.m',\n",
       " 'Test.ipynb',\n",
       " 'Test1.ipynb',\n",
       " 'testfor.m',\n",
       " 'Untitled.ipynb',\n",
       " 'untitled0.py',\n",
       " 'Untitled1.ipynb',\n",
       " 'untitled1.py',\n",
       " 'utest.py',\n",
       " 'What_do_you_like',\n",
       " 'what_do_you_like.asv',\n",
       " 'What_do_you_like.ipynb',\n",
       " 'what_do_you_like.m',\n",
       " 'What_do_you_like.py',\n",
       " '__pycache__']"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.listdir()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['EulerProject-checkpoint.ipynb',\n",
       " 'EulerProject_39-checkpoint.ipynb',\n",
       " 'Test-checkpoint.ipynb',\n",
       " 'Test1-checkpoint.ipynb',\n",
       " 'Untitled-checkpoint.ipynb',\n",
       " 'Untitled1-checkpoint.ipynb',\n",
       " 'What_do_you_like-checkpoint.ipynb']"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.chdir('.ipynb_checkpoints/')\n",
    "os.listdir()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "''"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.path.dirname('EulerProject-checkpoint.ipynb')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'EulerProject-checkpoint.ipynb'"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.path.relpath('EulerProject-checkpoint.ipynb')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def findfiles(stri,path):\n",
    "    '''找到path目录下及其及目录下的所有包含stri的文件并打印其相对路径'''\n",
    "    abspath = os.path.abspath(path)\n",
    "    a = os.listdir(abspath)\n",
    "    for i in a:\n",
    "        if os.path.isfile(i) and stri in i:\n",
    "            print(os.path.relpath(i))\n",
    "        if os.path.isdir(i):\n",
    "            findfiles(stri,i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "findfiles('.py','.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['EulerProject-checkpoint.ipynb',\n",
       " 'EulerProject_39-checkpoint.ipynb',\n",
       " 'Test-checkpoint.ipynb',\n",
       " 'Test1-checkpoint.ipynb',\n",
       " 'Untitled-checkpoint.ipynb',\n",
       " 'Untitled1-checkpoint.ipynb',\n",
       " 'What_do_you_like-checkpoint.ipynb']"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.listdir('.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "os.chdir('..')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'D:\\\\workplace\\\\EulerProject'"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.path.abspath('.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ".spyderproject\n",
      ".spyderworkspace\n",
      "euler43.py\n",
      "euler44.py\n",
      "euler45.py\n",
      "euler46.py\n",
      "euler47.py\n",
      "euler48.py\n",
      "euler49.py\n",
      "euler50.py\n",
      "euler51.py\n",
      "EulerProject.ipynb\n",
      "EulerProject_39.ipynb\n",
      "findFile.py\n",
      "Test.ipynb\n",
      "Test1.ipynb\n",
      "Untitled.ipynb\n",
      "untitled0.py\n",
      "Untitled1.ipynb\n",
      "untitled1.py\n",
      "utest.py\n",
      "What_do_you_like.ipynb\n",
      "What_do_you_like.py\n"
     ]
    }
   ],
   "source": [
    "findfiles('py','.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def findfiles(stri,path):\n",
    "    '''找到path目录下及其及目录下的所有包含stri的文件并打印其相对路径'''\n",
    "    abspath = os.path.abspath(path)\n",
    "    a = os.listdir(abspath)\n",
    "    for i in a:\n",
    "        if os.path.isfile(i) and stri in i:\n",
    "            print(os.path.relpath(i))\n",
    "        if os.path.isdir(i):\n",
    "            findfiles(stri,os.path.abspath(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ".spyderproject\n",
      ".spyderworkspace\n",
      "euler43.py\n",
      "euler44.py\n",
      "euler45.py\n",
      "euler46.py\n",
      "euler47.py\n",
      "euler48.py\n",
      "euler49.py\n",
      "euler50.py\n",
      "euler51.py\n",
      "EulerProject.ipynb\n",
      "EulerProject_39.ipynb\n",
      "findFile.py\n",
      "Test.ipynb\n",
      "Test1.ipynb\n",
      "Untitled.ipynb\n",
      "untitled0.py\n",
      "Untitled1.ipynb\n",
      "untitled1.py\n",
      "utest.py\n",
      "What_do_you_like.ipynb\n",
      "What_do_you_like.py\n"
     ]
    }
   ],
   "source": [
    "findfiles('py','.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def findfiles(stri,path):\n",
    "    '''找到path目录下及其及目录下的所有包含stri的文件并打印其相对路径'''\n",
    "    abspath = os.path.abspath(path)\n",
    "    a = os.listdir(abspath)\n",
    "    for i in a:\n",
    "        if os.path.isfile(i) and stri in i:\n",
    "            print(os.path.relpath(i))\n",
    "        if os.path.isdir(i):\n",
    "            print('isdir:'+ i)\n",
    "            findfiles(stri,os.path.abspath(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "isdir:.git\n",
      "isdir:.ipynb_checkpoints\n",
      ".spyderproject\n",
      ".spyderworkspace\n",
      "euler43.py\n",
      "euler44.py\n",
      "euler45.py\n",
      "euler46.py\n",
      "euler47.py\n",
      "euler48.py\n",
      "euler49.py\n",
      "euler50.py\n",
      "euler51.py\n",
      "EulerProject.ipynb\n",
      "EulerProject_39.ipynb\n",
      "findFile.py\n",
      "Test.ipynb\n",
      "Test1.ipynb\n",
      "Untitled.ipynb\n",
      "untitled0.py\n",
      "Untitled1.ipynb\n",
      "untitled1.py\n",
      "utest.py\n",
      "What_do_you_like.ipynb\n",
      "What_do_you_like.py\n",
      "isdir:__pycache__\n"
     ]
    }
   ],
   "source": [
    "findfiles('py','.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'D:\\\\workplace\\\\EulerProject\\\\.ipynb_checkpoints'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.path.abspath('.ipynb_checkpoints')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'D:\\\\workplace\\\\EulerProject\\\\.ipynb_checkpoints'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "os.path.abspath('D:\\\\workplace\\\\EulerProject\\\\.ipynb_checkpoints')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['EulerProject-checkpoint.ipynb',\n",
       " 'EulerProject_39-checkpoint.ipynb',\n",
       " 'Test-checkpoint.ipynb',\n",
       " 'Test1-checkpoint.ipynb',\n",
       " 'Untitled-checkpoint.ipynb',\n",
       " 'Untitled1-checkpoint.ipynb',\n",
       " 'What_do_you_like-checkpoint.ipynb']"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " os.listdir('D:\\\\workplace\\\\EulerProject\\\\.ipynb_checkpoints')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def findfiles(stri,path):\n",
    "    '''找到path目录下及其及目录下的所有包含stri的文件并打印其相对路径'''\n",
    "    abspath = os.path.abspath(path)\n",
    "    a = os.listdir(abspath)\n",
    "    for i in a:\n",
    "        if os.path.isfile(i) and stri in i:\n",
    "            print(os.path.relpath(i))\n",
    "        if os.path.isdir(i):\n",
    "            return findfiles(stri,os.path.abspath(i))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "findfiles('py','.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def findfiles(stri,path):\n",
    "    '''找到path目录下及其及目录下的所有包含stri的文件并打印其相对路径'''\n",
    "    abspath = os.path.abspath(path)\n",
    "    a = os.listdir(abspath)\n",
    "    for i in a:\n",
    "        if os.path.isfile(i) and stri in i:\n",
    "            print(os.path.relpath(i))\n",
    "        if os.path.isdir(i):\n",
    "            findfiles(stri,os.path.abspath(i))"
   ]
  }
 ],
 "metadata": {
  "anaconda-cloud": {},
  "kernelspec": {
   "display_name": "Python [Root]",
   "language": "python",
   "name": "Python [Root]"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
